package com.zkingsoft.laqeelin.service.impl;

import com.matrix.core.constance.SystemErrorCode;
import com.zkingsoft.laqeelin.service.BizQrcodeService;

import org.springframework.stereotype.Service;

import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.UUIDUtil;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.tools.WebUtil;
import com.zkingsoft.laqeelin.dao.BizQrcodeDao;

import org.springframework.beans.factory.annotation.Autowired;

import com.matrix.core.tools.ModelUtils;

import java.util.List;
import java.util.Map;

import com.zkingsoft.laqeelin.bean.BizQrcode;

/**
 * @description service接口实现类(二维码记录表)
 * @author 何明
 * @date 2018-09-26 18:31
 */
@Service
public class  BizQrcodeServiceImpl implements  BizQrcodeService{

	
	@Autowired
	private BizQrcodeDao bizQrcodeDao;
	
	
	@Override
	public int add(BizQrcode bizQrcode){
		// 设置基本字段信息
		/*SysUsers loginUser = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
		bizQrcode.setCreateBy(loginUser.getSuName());
		bizQrcode.setUpdateBy(loginUser.getSuName());
		bizQrcode.setCodeId(UUIDUtil.getRandomID());
		return bizQrcodeDao.insert(bizQrcode);*/
		return bizQrcodeDao.insert(bizQrcode);
	}
	
	@Override
	public int batchAdd(List<BizQrcode>  bizQrcodeList) {
		//这里没有做基本字段的设置，如有需要请自己实现	
		int num = 0;
		int c = 10000;
		int size = bizQrcodeList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= bizQrcodeList.size() ? bizQrcodeList.size() : end;
			List<BizQrcode> insertList = bizQrcodeList.subList(begin, end);
			num += bizQrcodeDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(BizQrcode oldBizQrcode
	,BizQrcode newBizQrcode){
	
		Map<String, Object> modifyMap = null;
		try {
			if (!ModelUtils.isModified(oldBizQrcode, newBizQrcode)) {
				return MatrixConstance.DML_SUCCESSS;
			}
			modifyMap = ModelUtils.comparePojo2Map(oldBizQrcode, newBizQrcode);
		} catch (Exception e) {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newBizQrcode);
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("codeId", oldBizQrcode.getCodeId());
			bizQrcodeDao.updateByMap(modifyMap);
		}
		return MatrixConstance.DML_SUCCESSS;
	}
	
	@Override
	public int modifyByModel(BizQrcode bizQrcode){
	
		return bizQrcodeDao.updateByModel(bizQrcode);
	
	}
	
	
	
	/*@Override
	public int remove(List<Long> list){
	
		return bizQrcodeDao.deleteByIds(list);
	
	}*/

	@Override
	public int removeById(Long codeId){
	
		return bizQrcodeDao.deleteById(codeId);
	
	}
	
	@Override
	public int removeByModel(BizQrcode bizQrcode){
	
		return bizQrcodeDao.deleteByModel(bizQrcode);
	
	}
	
	
	@Override
	public List<BizQrcode> findInPage(BizQrcode bizQrcode,  PaginationVO pageVo){
	
		return bizQrcodeDao.selectInPage(bizQrcode , pageVo);
	
	}
	
	@Override
	public List<BizQrcode> findByModel(BizQrcode bizQrcode){
	
		return bizQrcodeDao.selectByModel(bizQrcode);
	
	}
	
	@Override
	public int  findTotal(BizQrcode bizQrcode){
	
		return bizQrcodeDao.selectTotalRecord(bizQrcode);
	
	}
	
	@Override
	public BizQrcode  findById(Long codeId){
	
		return bizQrcodeDao.selectById(codeId);
	
	}

	@Override
	public int remove(List<String> list) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int removeById(String id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public BizQrcode findById(String id) {
		// TODO Auto-generated method stub
		return null;
	}

   	
	
	
}